﻿using IBLL;
using IDAL;
using Model;

namespace BLL
{
    public class MemberBLL:IMemberBLL
    {
        public MemberBLL(IBaseDAL<Member> dAL,IBaseDAL<House> dAL1)
        {
            DAL = dAL;
            DAL1 = dAL1;
        }

        public IBaseDAL<Member> DAL { get; }
        public IBaseDAL<House> DAL1 { get; }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="m">参数</param>
        /// <returns>可影响行数</returns>
        public Task<int> MAdd(Member m)
        {
            return DAL.AddAsync(m);
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="HId">所属门店下拉框</param>
        /// <param name="Num">下单次数次数</param>
        /// <param name="MDate">会员时间</param>
        /// <returns>可影响行数</returns>
        public dynamic MShow(int HId, int Num, DateTime? MDate)
        {
            var date = DAL.GetAll();
            var leve = DAL1.GetAll();
            var list = from a in date
                       join b in leve
                       on a.HId equals b.HId
                       select new
                       {
                           a.Id,
                           a.Name,
                           a.Tel,
                           a.Sex,
                           a.Num,
                           a.Age,
                           a.SName,
                           a.App,
                           a.Bei,
                           a.MDate,
                           b.HId,
                           b.HName
                       };
            if (HId > 0)
            {
                list = list.Where(x => x.HId == HId);
            }
            if (Num > 0)
            {
                list = list.Where(x => x.Num == Num);
            }
            if (MDate!=null)
            {
                list = list.Where(x => x.MDate == MDate);
            }
            return list.ToList();
        }
        /// <summary>
        /// 下拉框
        /// </summary>
        /// <returns>可影响行数</returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<House> Xia()
        {
            return DAL1.GetAll().ToList();
        }
    }
}
